import { ref, watch } from "vue";

const useFilterComponents = (props, emits) => {
  const filterListData = ref([]);

  const handelReset = () => {
    filterListData.value[0].value = [];
    emits("handelFilterData", filterListData.value);
  };
  const handelConfirm = () => {
    emits("handelFilterData", filterListData.value);
  };

  watch(
    () => props.filterList,
    newVal => {
      filterListData.value = [...newVal];
    },
    { deep: true, immediate: true }
  );

  return {
    handelReset,
    handelConfirm,
    filterListData
  };
};

export default useFilterComponents;
